<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<link rel="stylesheet" type="text/css"
		href="../../resources/estilo.css" />
	<title>Gerenciamento de Turmas!</title>
</h:head>

<h:body>
	<ui:include src="menu.xhtml" />

	<h2>Gerenciamento de Turmas</h2>
	
	<h:form>
		<p:messages />
		<p:dataTable value="#{turmaManager.turmas}" var="turmas"
			paginator="true" rows="10">
			<f:facet name="header">
				<p:outputPanel style="margin-left: 600px;">
					<p:commandButton value="Nova turma"
						oncomplete="dialogGerTurma.show()" />
				</p:outputPanel>

			</f:facet>
			<p:column>
				<f:facet name="header">
					<h:outputText value="Curso" />
				</f:facet>
				<h:outputText id="curso" value="#{turmas.curso.nome}" />
			</p:column>

			<p:column>
				<f:facet name="header">
					<h:outputText value="Dia" />
				</f:facet>
				<h:outputText value="#{turmas.diaSemana}" />
			</p:column>
			<p:column style="width: 45px;">
				<f:facet name="header">
					<h:outputText value="Inicio" />
				</f:facet>
				<h:outputText value="#{turmas.dataInicio}" />
			</p:column>

			<p:column style="width: 45px;">
				<f:facet name="header">
					<h:outputText value="Conclusão" />
				</f:facet>
				<h:outputText value="#{turmas.dataConclusao}">
					<f:convertDateTime pattern="dd/MM/yyyy" />
				</h:outputText>
			</p:column>

			<p:column style="width: 20px;">
				<f:facet name="header">
					<h:outputText value="Vagas" />
				</f:facet>
				<h:outputText value="#{turmas.numeroVagas}" />
			</p:column>

			<p:column>
				<f:facet name="header">
					<h:outputText value="Situação" />
				</f:facet>
				<h:outputText value="#{turmas.situacao}" />
			</p:column>
			
			<p:column>
				<f:facet name="header">
					<h:outputText value="Sala" />
				</f:facet>
				<h:outputText value="#{turmas.sala}" />
			</p:column>

			<p:column>
				<f:facet name="header">
					<h:outputText value="Editar" />
				</f:facet>
				<p:commandButton action="#{turmaManager.prepararUpdate(turmas)}"
					value="Editar" update="cadturmas"
					oncomplete="dialogGerTurma.show()" />
			</p:column>

			<p:column>
				<f:facet name="header">
					<h:outputText value="Excluir" />
				</f:facet>
				<p:commandButton ajax="false" onclick="confirmation.show()"
					value="Excluir" type="button" />

				<p:confirmDialog message="Deseja realmente excluir essa turma?"
					header="Deletando turma..." severity="alert"
					widgetVar="confirmation">

					<p:commandButton value="Deletar" update="messages"
						oncomplete="confirmation.hide()" ajax="false"
						actionListener="#{turmaManager.excluir(turmas)}" />
					<p:commandButton value="Cancelar" onclick="confirmation.hide()"
						type="button" />

				</p:confirmDialog>
			</p:column>
		</p:dataTable>
	</h:form>

	<p:separator />

	<div id="table_curso">
		<h:form>
			<p:commandLink value="Novo Curso" oncomplete="dialogGerCurso.show()" />
			<p:dataTable value="#{cursoManager.listaCurso}" var="curso"
				paginator="true" rows="5">

				<p:column>
					<f:facet name="header">
						<h:outputText value="Curso" />
					</f:facet>
					<h:outputText value="#{curso.nome}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Descrição" />
					</f:facet>
					<h:outputText value="#{curso.descricao}" />
				</p:column>

				<p:column style="width: 90px;">
					<f:facet name="header">
						<h:outputText value="Editar" />
					</f:facet>
					<p:commandButton action="#{cursoManager.preparaCurso(curso)}"
						value="Editar" update="cadcurso"
						oncomplete="dialogGerCurso.show()" />
				</p:column>
			</p:dataTable>
		</h:form>
	</div>
	<p:dialog header="Cadastro de turmas" widgetVar="dialogGerTurma"
		width="500" resizable="false" showEffect="slide"
		onCloseUpdate="cadturmas">
		<h:form id="cadturmas">
			<h:panelGrid id="infosTurma" columns="2" bgcolor="white">
				<h:outputText value="Curso: " />
				<h:selectOneMenu label="turma" value="#{turmaManager.idCurso}" required="true" converterMessage="Selecione o curso">
					<f:selectItem id="curso" itemLabel="selecione o curso" itemValue="" />
					<f:selectItems value="#{turmaManager.cursos}" var="cursos"
						itemLabel="#{cursos.nome}" itemValue="#{cursos.id}" />
				</h:selectOneMenu>
				
				<h:outputText value="Professor: " />
				<h:selectOneMenu value="#{turmaManager.idProfessor}" required="true" converterMessage="Selecione o professor responsavel pela sala">
					<f:selectItem itemLabel="selecione o professor" itemValue="" />
					<f:selectItems value="#{turmaManager.professores}" var="professor"
						itemLabel="#{professor.nome} #{professor.sobrenome}" itemValue="#{professor.id}" />
				</h:selectOneMenu>
				

				<h:outputText value="Situação: "/>
				<h:selectOneMenu value="#{turmaManager.turma.situacao}" required="true">
					<f:selectItem itemLabel="Aberto" itemValue="Aberto" />
					<f:selectItem itemLabel="Em Andamento" itemValue="Em Andamento" />
					<f:selectItem itemLabel="Concluido" itemValue="Concluido" />
				</h:selectOneMenu>
				
				<h:outputText value="Sala: "/>
				<h:selectOneMenu value="#{turmaManager.turma.sala}" required="true">
					<f:selectItem itemLabel="Selecione a sala" itemValue="" />
					<f:selectItem itemLabel="1" itemValue="1" />
					<f:selectItem itemLabel="2" itemValue="2" />
					<f:selectItem itemLabel="3" itemValue="3" />
					<f:selectItem itemLabel="4" itemValue="4" />
					<f:selectItem itemLabel="5" itemValue="5" />
					<f:selectItem itemLabel="6" itemValue="6" />
				</h:selectOneMenu>

				<h:outputText value="Dia da semana: " />
				<h:selectOneMenu value="#{turmaManager.turma.diaSemana}" required="true" requiredMessage="selecione o(s) dia(s) em que haverá aula">
					<f:selectItem itemLabel="Selecione" itemValue="" />
					<f:selectItem itemLabel="Seg-Qua-Set"
						itemValue="Segunda, Quarta e Sexta" />
					<f:selectItem itemLabel="Terça - Quinta" itemValue="Terca e Quinta" />
					<f:selectItem itemLabel="Sábado" itemValue="Sábado" />
				</h:selectOneMenu>

				<h:outputText value="Data de Inicio: "  />
				<p:calendar value="#{turmaManager.turma.dataInicio}" required="true" requiredMessage="adicione a data de incio da turma"/>
				<h:outputText value="Data de Conclusão: " />
				<p:calendar value="#{turmaManager.turma.dataConclusao}" required="true" requiredMessage="adicione a data de conclusão da turma"/>
				<h:outputText value="numero de vagas: " />
				<p:inputText value="#{turmaManager.turma.numeroVagas}" size="4" required="true" requiredMessage="adicione o número de vagas"/>

				<h:inputHidden value="#{turmaManager.turma.id}" />

				<h:commandButton action="#{turmaManager.save}" value="Salvar" ajax="false" />
			</h:panelGrid>
		</h:form>
	</p:dialog>

	<p:dialog header="Cadastro de curso" widgetVar="dialogGerCurso"
		width="500" resizable="false" showEffect="slide"
		onCloseUpdate="cadcurso">

		<h:form id="cadcurso">
			<h:panelGrid id="infosCurso" columns="2">

				
				<h:outputText value="Nome: " />
				<p:inputText id="nome" value="#{cursoManager.curso.nome}" required="true" requiredMessage="Preencha o campo nome"/>
	
				<h:outputText value="Descrição: " />
				<p:inputTextarea id="descricao" value="#{cursoManager.curso.descricao}" required="true" requiredMessage="Preencha o campo descrição"
					style="width:300px;height:50px;" />
					

				<h:inputHidden value="#{cursoManager.curso.id}" />
				<h:commandButton action="#{cursoManager.save}" value="Salvar" />
			</h:panelGrid>
		</h:form>
	</p:dialog>
	
</h:body>
</html>